package com.erp.controller;

import com.erp.entity.result.Result;
import com.erp.entity.result.ResultStatus;
import com.erp.entity.vo.CitySaleVO;
import com.erp.entity.vo.GoodsSaleVO;
import com.erp.entity.vo.OutputAndInputVO;
import com.erp.service.BreakageService;
import com.erp.service.OutputService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.websocket.server.PathParam;
import java.util.List;


/**
 * @author pengyujin
 * 全部图表接口
 * @date 2020/11/14 17:09
 */
@RestController
@RequestMapping("/chart")
public class ChartController {
    
    @Autowired
    private OutputService outputService;
    
    @Autowired
    private BreakageService breakageService;

    /**
     * 按时间返回出货量前10
     * @param start
     * @param end
     * @return
     */
    @GetMapping("/getOutputChart")
    public Result getOutputChart(@PathParam("start")String start, @PathParam("end") String end) {
        // 自定义VO,返回图表信息
        List<GoodsSaleVO> list = outputService.getGoodsSale(start, end);
        return new Result(ResultStatus.SUCCESS, list);
    }

    /**
     * 统计年度报损货物走势
     * @param
     * @return
     */
    @GetMapping("/getBreakageSituation")
    public Result getBreakageSituation(@PathParam("start")String start, @PathParam("end") String end) {
        return new Result(ResultStatus.SUCCESS, breakageService.getBreakageSituation(start, end));
    }

    /**
     * 返回当前库存告急的货物 < 100
     * @return
     */
    @GetMapping("/get")
    public Result get() {
        return new Result(ResultStatus.SUCCESS, null);
    }

    /**
     * 全国城市销量分布统计
     */
    @GetMapping("/getCitySalesSituation")
    public Result getCitySalesSituation(@PathParam("start")String start, @PathParam("end") String end) {
        List<CitySaleVO> res = outputService.getCitySalesSituation(start, end);
        for (CitySaleVO r : res) {
            if (!r.getName().isEmpty() && r.getName() != null) {
                r.setName(r.getName().split("市")[0]);
            }
        }
        return new Result(ResultStatus.SUCCESS, res);
    }

    /**
     * 出入库量和平均价格分布统计
     */
    @GetMapping("/getOutputAndInputSituation")
    public Result getOutputAndInputSituation(@PathParam("start")String start, @PathParam("end") String end) {
        List<OutputAndInputVO> res = outputService.getOutputAndInputSituation(start, end);
        return new Result(ResultStatus.SUCCESS, res);
    }
}
